package com.study.spring.spel;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

/**
 * [SpEL表达式总结 \- 简书](https://www.jianshu.com/p/e0b50053b5d3)
 */
public class SpelTest {
    @Value("#{表达式}")
    private String name;
    public static void main(String[] args) {

//        <bean id="xxx" class="com.java.XXXXX.xx">
//    <!-- 同@Value,#{}内是表达式的值，可放在property或constructor-arg内 -->
//    <property name="arg" value="#{表达式}">
//</bean>

        ExpressionParser parser = new SpelExpressionParser();
        Expression expression = parser.parseExpression("表达式");
        System.out.println(expression.getValue());

        expression = parser.parseExpression("'Hello work'");
        System.out.println(expression.getValue());

        expression = parser.parseExpression("'Hello work'.concat('!')");
        System.out.println(expression.getValue());
    }
}
